import _thread

class AtomicInteger:
    def __init__(self, initialValue):
        if not isinstance(initialValue, int):
            raise TypeError
        self.value = initialValue
        self.lock = _thread.allocate_lock()
    
    def get(self):
        return self.value
    
    def set(self, newValue):
        self.value = newValue
        
    def getAndSet(self, newValue):
        with self.lock:
            oldValue = self.value
            self.value = newValue
        return oldValue
    
    def getAndIncrement(self):
        with self.lock:
            oldValue = self.value
            self.value += 1
        return oldValue
    
    def getAndDecrement(self):
        with self.lock:
            oldValue = self.value
            self.value -= 1
        return oldValue
    
    def getAndAdd(self, delta):
        with self.lock:
            oldValue = self.value
            self.value += delta
        return oldValue
    
    def incrementAndGet(self):
        with self.lock:
            self.value += 1
            newValue = self.value
        return newValue
    
    def decrementAndGet(self):
        with self.lock:
            self.value -= 1
            newValue = self.value
        return newValue
    
    def addAndGet(self, delta):
        with self.lock:
            self.value += delta
            newValue = self.value
        return newValue
    
    